import type { Directive } from 'vue'

const preventEvent = (event: Event) => {
  event.preventDefault()
}

/**
 * 禁止复制、剪切、粘贴指令
 */
export const NoCopyPaste: Directive = {
  mounted(el: HTMLElement) {
    el.addEventListener('copy', preventEvent)
    el.addEventListener('cut', preventEvent)
    el.addEventListener('paste', preventEvent)
  },
  unmounted(el: HTMLElement) {
    el.removeEventListener('copy', preventEvent)
    el.removeEventListener('cut', preventEvent)
    el.removeEventListener('paste', preventEvent)
  }
}
